package com.zzb.servlet;



import com.zzb.model.ProductModel;
import com.zzb.model.ProductTypeModel;
import com.zzb.service.ProductService;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.nio.charset.StandardCharsets;
import java.util.List;

@WebServlet("/product")
public class ProductServlet extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws IOException, ServletException {
        //1.处理乱码
        req.setCharacterEncoding(StandardCharsets.UTF_8.toString());
        resp.setCharacterEncoding(StandardCharsets.UTF_8.toString());


        //2.得到前端数据

        //3.将数据封装到model


        //4.处理服务逻辑关系
        //得到产品信息
        ProductService productService = new ProductService();

        //5.得到处理返回值
        //得到产品信息
        List<ProductModel> productModelList = productService.getProductModelList();
        //得到产品类型名称
        List<ProductTypeModel> productTypeModelsList = productService.getProductTypeModelList();

        req.setAttribute("productModelList", productModelList);
        req.setAttribute("productTypeModelsList", productTypeModelsList);

        //6.将数据返回到前端
        req.getRequestDispatcher("/jsp/product.jsp").forward(req, resp);
    }
}
